


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
    void merge1(vector<int>& nums1, int m, vector<int>& nums2, int n)
    {
        vector<int> ans;
        ans.reserve(m + n);

        int l1 = 0, l2 = 0;
        while (l1 < m && l2 < n)
        {
            if (nums1[l1] <= nums2[l2])
                ans.push_back(nums1[l1++]);
            else
                ans.push_back(nums2[l2++]);
        }

        while (l1 < m)
            ans.push_back(nums1[l1++]);
        while (l2 < n)
            ans.push_back(nums2[l2++]);

        nums1 = ans;
    }

    void merge2(vector<int>& nums1, int m, vector<int>& nums2, int n)
    {
        int l1 = m, l2 = 0;

        while (l2 < n)
        {
            nums1[l1++] = nums2[l2++];
        }

        sort(nums1.begin(), nums1.end());
    }

    void merge3(vector<int>& nums1, int m, vector<int>& nums2, int n)
    {
        int end = m + n - 1;
        int l1 = m - 1, l2 = n - 1;

        if (0 == m)
        {
            nums1 = nums2;
        }
        else
        {
            while (l1 > -1 && l2 > -1)
            {
                if (nums1[l1] >= nums2[l2])
                    nums1[end--] = nums1[l1--];
                else
                    nums1[end--] = nums2[l2--];
            }

            while (l2 > -1)
            {
                nums1[end--] = nums2[l2--];
            }
        }
    }
};

void Test1()
{
    vector<int> v1 = { 1, 2, 3, 0, 0, 0 };
    vector<int> v2 = { 2, 5, 6 };

    Solution().merge2(v1, v1.size()-v2.size(), v2, v2.size());
}

int main()
{
    Test1();


	return 0;
}